#include "Thread.hpp"
#include "ThreadPool.hpp"
#include "Task.hpp"
#include <memory>

int main()
{
    // std::unique_ptr<ThreadPool<Task>> tp(new ThreadPool<Task>());
    // tp->run();
    // 启动线程池，因为任务队列为空，持有锁的线程在条件等待

    // 单例线程池
    ThreadPool<Task> *tp = ThreadPool<Task>::getInstance();
    ThreadPool<Task> *tp1 = ThreadPool<Task>::getInstance();
    ThreadPool<Task> *tp2 = ThreadPool<Task>::getInstance();
    ThreadPool<Task> *tp3 = ThreadPool<Task>::getInstance();
    ThreadPool<Task> *tp4 = ThreadPool<Task>::getInstance();
    std::cout << tp << std::endl;
    std::cout << tp1 << std::endl;
    std::cout << tp2 << std::endl;
    std::cout << tp3 << std::endl;
    std::cout << tp4 << std::endl;
    tp->run();

    int x;
    int y;
    char op;

    while (1)
    {
        std::cout << "请输入数据1#";
        std::cin >> x;
        std::cout << "请输入数据2#";
        std::cin >> y;
        std::cout << "请输入运算符（+-*/%）#";
        std::cin >> op;

        // 构造一个任务
        Task t(x, y, op, mymath);

        // 把任务放入线程池的任务队列
        tp->push(t);
        // 任务一旦放入，会唤醒条件等待的线程

        sleep(1);
    }
}